<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>等级及分销列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-body" pad15>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{:url('index')}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
			{type:"checkbox"},
          {field: 'id', title: 'ID','width':60},
          {field: 'name', title: '等级名称','width':160,'templet':'<div>{{d.name}}{{# if(d.isdefault==1){ }}<span style="color:#ee8888;font-size:12px">[默认等级]</span>{{# } }}</div>'},
          {field: 'applytj', title: '申请条件'},
          {field: 'apply_paymoney', title: '申请加盟费','width':100,'templet':'<div>￥{{d.apply_paymoney}}</div>'},
          {field: 'uptj', title: '升级条件(成为该等级的条件)'},
          {field: 'commission', title: '提成比例','width':200},
      {field: 'operation', title: '操作',templet: '<div><button class="table-btn" onclick="chooselevel(\'{{d.id}}\')">选择</button></div>',align:'center'}
    ]]
  });
	function chooselevel(id){
		var index = layer.load();
		$.post("{:url('chooselevel')}",{id:id},function(res){
			layer.close(index);
            {if input('param.callback')}
                window.parent.{$Request.param.callback}(res.data,"{$Request.param.args}");
            {else}
                window.parent.chooselevel(res.data,"{$Request.param.args}");
            {/if}
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		})
	}
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	</script>
</body>
</html>